
import requests
import json
import utils
import config
import utils_longhu


#依据提起和股票代码获取龙虎榜详情数据
#q·3日的和单日的如何区分？
def get_longhu_details(data_date,stock_code):
    #1、取数
    #设置请求的头
    #请求东方财富获取数据


    #返回非标准json，预处理
    headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"}
    url=config.getConfig()["url"]["longhu_stock_details"]
    url_for_getDetails = url.replace("yyyy-mm-dd", data_date).replace("xxxxxx", stock_code)
    print(url_for_getDetails)
    res = requests.get(url_for_getDetails,headers)

    ##result = res.text.split("jQuery112406326540387216384_1711515195823")[1].split("(")[1].split(");")[0]
    result = res.text
    result_json = json.loads(result)
    print(result_json)
    #2、存储到mysql
    #utils.save_quote_txn(result_json['data']['diff'])
    #print(result_json)
    #转成二维数组
    #longhu_list=utils.jsonlist2matrix(result_json['data']['items'])
    longhu_details=result_json['data'];
    print(longhu_details)
    utils_longhu.save_longhu_detail(longhu_details,data_date,stock_code)
    #落表
    #utils.save_quote_txn_bath(result_value_matrix)

get_longhu_details("2025-01-02",'002640')
